/// 图片项模型
///
/// 表示单张照片的信息
class PhotoItem {
  /// 图片唯一标识
  final String id;

  /// 图片缩略图路径
  final String thumbnailPath;

  /// 图片原始路径
  final String originalPath;

  /// 图片文件名
  final String fileName;

  /// 拍摄时间
  final DateTime captureTime;

  /// 图片大小（字节）
  final int fileSize;

  /// 是否被选中
  final bool isSelected;

  /// 上传状态（0: 未上传, 1: 上传中, 2: 已上传, 3: 失败）
  final int uploadStatus;

  const PhotoItem({
    required this.id,
    required this.thumbnailPath,
    required this.originalPath,
    required this.fileName,
    required this.captureTime,
    required this.fileSize,
    this.isSelected = false,
    this.uploadStatus = 0,
  });

  /// 创建副本
  PhotoItem copyWith({
    String? id,
    String? thumbnailPath,
    String? originalPath,
    String? fileName,
    DateTime? captureTime,
    int? fileSize,
    bool? isSelected,
    int? uploadStatus,
  }) {
    return PhotoItem(
      id: id ?? this.id,
      thumbnailPath: thumbnailPath ?? this.thumbnailPath,
      originalPath: originalPath ?? this.originalPath,
      fileName: fileName ?? this.fileName,
      captureTime: captureTime ?? this.captureTime,
      fileSize: fileSize ?? this.fileSize,
      isSelected: isSelected ?? this.isSelected,
      uploadStatus: uploadStatus ?? this.uploadStatus,
    );
  }

  /// 格式化文件大小
  String get formattedFileSize {
    if (fileSize < 1024) {
      return '$fileSize B';
    } else if (fileSize < 1024 * 1024) {
      return '${(fileSize / 1024).toStringAsFixed(1)} KB';
    } else {
      return '${(fileSize / (1024 * 1024)).toStringAsFixed(1)} MB';
    }
  }

  /// 获取上传状态描述
  String get uploadStatusText {
    switch (uploadStatus) {
      case 0:
        return '未上传';
      case 1:
        return '上传中';
      case 2:
        return '已上传';
      case 3:
        return '失败';
      default:
        return '未知';
    }
  }

  @override
  String toString() {
    return 'PhotoItem(id: $id, fileName: $fileName, status: $uploadStatusText)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is PhotoItem &&
        other.id == id &&
        other.thumbnailPath == thumbnailPath &&
        other.originalPath == originalPath &&
        other.fileName == fileName &&
        other.captureTime == captureTime &&
        other.fileSize == fileSize &&
        other.isSelected == isSelected &&
        other.uploadStatus == uploadStatus;
  }

  @override
  int get hashCode {
    return Object.hash(
      id,
      thumbnailPath,
      originalPath,
      fileName,
      captureTime,
      fileSize,
      isSelected,
      uploadStatus,
    );
  }
}
